﻿using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Lottery.Client.SL.Controls;
using Lottery.Client.SL.Mode;

namespace Lottery.Client.SL
{
    public class CulbViewMode
    {
        public static GameKind GameKind;
        public static Game SelectGame;
        public static List<Keyboard> KeyList;
        public IKeyboard IKey;

        static CulbViewMode()
        {
            KeyList = new List<Keyboard>();
        }

        public bool CreateKeyboard(Canvas KeyCanvas)
        {
            bool result = false;
            KeyList.Clear();
            KeyCanvas.Children.Clear();
            string[] array =
                SelectGame.SelectGameMenu.SelectGameMode.PlayTypeKeyBoard.ToString(
                    CultureInfo.InvariantCulture).Split(new[]
                                                            {
                                                                ','
                                                            });
            if (array.Length > 1)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    var keyboard = new Keyboard();
                    keyboard.Tag = (array[i]);
                    Keyboard.SetText(keyboard, array[i]);
                    IKey = keyboard;
                    IKey.ShowKeyLable(keyboard);
                    if (array.Length < 5)
                    {
                        KeyCanvas.Height = (i*34.0 + keyboard.Height + 10.0);
                    }
                    else
                    {
                        KeyCanvas.Height = (i*34.0 + keyboard.Height - 5.0);
                    }
                    if (
                        SelectGame.SelectGameMenu.SelectGameMode.PlayTypeName.Contains(
                            "大小单双"))
                    {
                        for (int j = 0; j < keyboard.KeyNum.Children.Count; j++)
                        {
                            if (j > 3)
                            {
                                keyboard.KeyNum.Children[j].Visibility = Visibility.Collapsed;
                                keyboard.KeyCommand.Visibility = Visibility.Collapsed;
                            }
                        }
                        ((TextBlock) ((Canvas) keyboard.KeyNum.Children[0]).Children[3]).Text = "?";
                        ((TextBlock) ((Canvas) keyboard.KeyNum.Children[1]).Children[3]).Text = "?";
                        ((TextBlock) ((Canvas) keyboard.KeyNum.Children[2]).Children[3]).Text = "?";
                        ((TextBlock) ((Canvas) keyboard.KeyNum.Children[3]).Children[3]).Text = "?";
                    }
                    KeyList.Add(keyboard);
                    keyboard.SetValue(Canvas.TopProperty, i*36.0);
                    KeyCanvas.Children.Add(keyboard);
                }
            }
            else
            {
                //if (array[0].Trim().ToUpper() != "?")
                if(array[0].Trim()!="@")
                {
                    var keyboard2 = new Keyboard();
                    keyboard2.Tag = (array[0]);
                    Keyboard.SetText(keyboard2, array[0]);
                    IKey = keyboard2;
                    IKey.ShowKeyLable(keyboard2);
                    KeyList.Add(keyboard2);
                    KeyCanvas.Children.Add(keyboard2);
                    KeyCanvas.Height = keyboard2.Height + 10.0;
                }
                else
                {
                    DataCache.CurrentSchemeCache.InvestNum = 0;
                    result = true;
                    var textBlock = new TextBlock();
                    textBlock.Text = "请填写号码 <注：号码以\",\"分隔>";
                    textBlock.FontSize = 12.0;
                    textBlock.Foreground = new SolidColorBrush(Colors.White);
                    textBlock.SetValue(Canvas.TopProperty, 6.0);
                    KeyCanvas.Children.Add(textBlock);
                    var textBox = new TextBox();
                    textBox.Width = (KeyCanvas.Width + 2.0);
                    textBox.AcceptsReturn = true;
                    textBox.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
                    textBox.Height = (114.0);
                    textBox.TextWrapping = TextWrapping.Wrap;
                    textBox.SetValue(Canvas.TopProperty, 30.0);
                    KeyCanvas.Height = (150.0);
                    KeyCanvas.Children.Add(textBox);
                }
            }
            return result;
        }
    }
}